package file;

import java.io.File;
import java.io.FileFilter;

/**
 * @author liyang
 * @version 1.0
 * @package file
 * @file ListFilesDemo.java
 * @description
 * @time 2024-03-17 11:54
 */
public class ListFilesDemo {
    public static void main(String[] args) {
        File dir1 = new File("./");

/**
 * 以下是匿名内部类：只用一次
 * 灰色：还可以更精简，鼠标长放，软件自动精简！！！
 */
        FileFilter filter = new FileFilter() {
            @Override
            public boolean accept(File file) {
                String name = file.getName();
                //return (name.endsWith(".txt"));
                //return(name.contains("t"));
                return (name.startsWith("test"));
            }
        };


        if(dir1.isDirectory()){
            File[] sub = dir1.listFiles(filter);
            System.out.println(sub.length);
            for(File sub1 : sub){
                System.out.println(sub1.getName());
            }

        }



    }
}
